import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.net.*;

import javax.swing.JLabel;

public class Buttons extends JFrame {

    private Toolkit toolkit;
    JButton redx, check;
    static int i = 0;
    JLabel loginicon;

    public Buttons(final login log) {

        setTitle("Restaurant Master 2.0");
        setSize(800, 600);
        

        toolkit = getToolkit();
        Dimension size = toolkit.getScreenSize();
        setLocation((size.width - getWidth())/2, (size.height - getHeight())/2);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        JPanel panel = new JPanel();
        getContentPane().add(panel);

        panel.setLayout(null);
        
        JLabel loginlabel = new JLabel("Login:");
        loginlabel.setBounds(152, 165, 200, 200);
	
		final JTextField pinput = new JTextField("");
		pinput.setBounds(150, 275, 200, 25);
		
		loginicon = new JLabel();
		
		try {
			loginicon = new JLabel("", new ImageIcon(new URL("http://eden.rutgers.edu/~notsonic/javasrc/ricon.png")),JLabel.CENTER);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		loginicon.setBounds(45,25,300,192);
		
		panel.add(loginicon);
	
	
		JButton one = new JButton("1");
		one.setBounds(500,150,50,50);
		one.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
		             pinput.setText(pinput.getText()+"1");
		             
		           }
		        }
			)
			);
		
		JButton two = new JButton("2");
		two.setBounds(555,150,50,50);
		two.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
		             pinput.setText(pinput.getText()+"2");
		             
		           }
		        }
			)
			);
		
		JButton three = new JButton("3");
		three.setBounds(610,150,50,50);
		three.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
		             pinput.setText(pinput.getText()+"3");
		             
		           }
		        }
			)
			);
		
		JButton four = new JButton("4");
		four.setBounds(500,205,50,50);
		four.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
	             pinput.setText(pinput.getText()+"4");
	             
	           }
	        }
		)
		);
		
		JButton five = new JButton("5");
		five.setBounds(555,205,50,50);
		five.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
		             pinput.setText(pinput.getText()+"5");
		             
		           }
		        }
			)
			);
		
		JButton six = new JButton("6");
		six.setBounds(610,205,50,50);
		six.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
		             pinput.setText(pinput.getText()+"6");
		             
		           }
		        }
			)
			);
		
		JButton seven = new JButton("7");
		seven.setBounds(500,260,50,50);
		seven.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
		             pinput.setText(pinput.getText()+"7");
		             
		           }
		        }
			)
			);
		
		JButton eight = new JButton("8");
		eight.setBounds(555,260,50,50);
		eight.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
		             pinput.setText(pinput.getText()+"8");
		             
		           }
		        }
			)
			);
		
		JButton nine = new JButton("9");
		nine.setBounds(610,260,50,50);
		nine.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
		             pinput.setText(pinput.getText()+"9");
		             
		           }
		        }
			)
			);
		
		JButton zero = new JButton("0");
		zero.setBounds(555,315,50,50);
		zero.addActionListener((new ActionListener() {
	           public void actionPerformed(ActionEvent event) {
		             pinput.setText(pinput.getText()+"0");
		             
		           }
		        }
			)
			);
		
		try {
			redx = new JButton("",
					new ImageIcon
					(new URL("http://eden.rutgers.edu/~notsonic/javasrc/redx.gif")));
			redx.setBounds(500,315,50,50);
			redx.addActionListener((new ActionListener() {
		           public void actionPerformed(ActionEvent event) {
			             pinput.setText("");
			             
			           }
			        }
				)
				);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			check = new JButton("",
					new ImageIcon
					(new URL("http://eden.rutgers.edu/~notsonic/javasrc/gcheck.gif")));
			check.setBounds(610,315,50,50);
			
			check.addActionListener((new ActionListener() {
		          public void actionPerformed(ActionEvent event) {
		             //
		        	   log.setuid(pinput.getText());
		        	   pinput.setText("");
		        	   setVisible(false);
		             
		           }
		        }
			)
			);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

       JButton close = new JButton("Exit");
       close.setBounds(25, 515, 80, 30);
       close.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {
               System.exit(0);
        	   i=1;
        	   //System.out.println(i);
          }
       });
       
      
       
       
    	panel.add(close);
        panel.add(one);
        panel.add(two);
        panel.add(three);
        panel.add(four);
        panel.add(five);
        panel.add(six);
        panel.add(seven);
        panel.add(eight);
        panel.add(nine);
        panel.add(zero);
        panel.add(redx);
        panel.add(check);
        panel.add(pinput);
        panel.add(loginlabel);

    }
    
}